import 'package:flutter/material.dart';

///
///适配设计图大小 AdaptSize
///
class AdaptSize {
  static late MediaQueryData _mediaQueryData;
  static late double screenWidth;
  static late double screenHeight;

  ///设计图比例
  static late double proportion;

  ///在使用前必须调用
  static void initialize(BuildContext context, {double standardWidth = 375}) {
    _mediaQueryData = MediaQuery.of(context);
    screenWidth = _mediaQueryData.size.width;
    screenHeight = _mediaQueryData.size.height;
    proportion = screenWidth / standardWidth;
  }

  static double vw(double percent) {
    return percent * screenWidth * 0.01;
  }

  static double vh(double percent) {
    return percent * screenHeight * 0.01;
  }

  // 按照像素来设置
  static double px(double size) {
    return AdaptSize.proportion * size;
  }

  // 按照rxp来设置
  static double rpx(double size) {
    return (AdaptSize.proportion / 2) * size;
  }
}
